package com.ymttest.database.sharding.db.sqlwapper;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionUtils;

import com.ymt.core.tool.Logger;
import com.ymttest.database.sharding.config.DbShardingSourceConfig;
import com.ymttest.database.sharding.db.sharding.mapper.OrderMapper;
import com.ymttest.database.sharding.db.sharding.model.OrderExample;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;

/************************************************************************************

 ************************************************************************************/
public class OrderShardingWapper {

	public OrderExample example;

	public SqlSession shardingSqlSession;

	public OrderMapper orderMapper;

	public OrderShardingWapper() {

		try {

			shardingSqlSession = SqlSessionUtils
					.getSqlSession(DbShardingSourceConfig.getInstance()
							.shardingSessionFactory());

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		orderMapper = shardingSqlSession.getMapper(OrderMapper.class);

		example = new OrderExample();

	}
	/**根据订单号查询
	 * 
	 * @param orderId
	 * @return
	 */
	public List<OrderPo> selectbyOrderId(long orderId) {

		example.clear();

		example.createCriteria().andOrderIdEqualTo(orderId);

		List<OrderPo> orderPoList = orderMapper.selectByExample(example);

		return orderPoList;

	}

	/**根据主订单号查询
	 * 
	 * @param mainOrderId
	 * @return
	 */
	public List<OrderPo> selectbyMainOrderId(long mainOrderId) {

		example.clear();

		example.createCriteria().andMainOrderIdEqualTo(mainOrderId);

		List<OrderPo> orderPoList = orderMapper.selectByExample(example);

		return orderPoList;

	}

	public static void main(String args[]) {

		List<OrderPo> list = new OrderShardingWapper()
				.selectbyOrderId(1052810095L);

		Logger.info(list);

	}
}
